import type { Directive } from 'vue'
// 自定义指令
import * as directives from '@/directives'
import { useElementPlus } from '@/plugins/elementPlus'
import router from '@/router'
import { setupStore } from '@/store'
import { injectResponsiveStorage } from '@/utils/responsive'
import Table from '@pureadmin/table'
import { MotionPlugin } from '@vueuse/motion'
// import { useEcharts } from "@/plugins/echarts"
import mitt from 'mitt'
import { createApp } from 'vue'

import VueTippy from 'vue-tippy'
import App from './App.vue'
// 全局注册@iconify/vue图标库
import { FontIcon, IconifyIconOffline, IconifyIconOnline } from './components/ReIcon'
import { getPlatformConfig } from './config'
// 引入重置样式
import './styles/reset.scss'
// 导入公共样式
import '@/styles/index.scss'
// 一定要在main.ts中导入tailwind.css，防止vite每次hmr都会请求src/styles/index.scss整体css文件导致热更新慢的问题
import '@/styles/tailwind.css'
import 'element-plus/dist/index.css'

// 导入字体图标
import '@/assets/iconfont/iconfont.js'

// 全局注册vue-tippy

import '@/assets/iconfont/iconfont.css'
import 'tippy.js/dist/tippy.css'
import 'tippy.js/themes/light.css'

const app = createApp(App)
Object.keys(directives).forEach((key) => {
  app.directive(key, (directives as { [key: string]: Directive })[key])
})
app.component('IconifyIconOffline', IconifyIconOffline)
app.component('IconifyIconOnline', IconifyIconOnline)
app.component('FontIcon', FontIcon)
app.use(VueTippy)

getPlatformConfig(app).then(async (config) => {
  setupStore(app)
  app.use(router)
  await router.isReady()
  injectResponsiveStorage(app, config)
  app.use(MotionPlugin).use(useElementPlus).use(Table)
  // .use(useEcharts);
  app.mount('#app')
  app.config.globalProperties.eventBus = mitt()
})
